package com.algorithm.practice;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import com.algorithm.practice.fragment.ArrayFragment;
import com.algorithm.practice.fragment.LinkedListFragment;

public class AlgorithmExampleActivity extends AppCompatActivity {

    private static final String ALGORITHM = "algorithm";

    public static Intent createIntent(Context ctx, int algorithm) {
        Intent intent = new Intent(ctx, AlgorithmExampleActivity.class);
        intent.putExtra(ALGORITHM, algorithm);
        return intent;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_algorithm_sample);
        int algorithm = getIntent().getIntExtra(ALGORITHM, -1);
        if (algorithm != -1) {
            FragmentManager manager = getSupportFragmentManager();
            FragmentTransaction transaction = manager.beginTransaction();
            switch (algorithm) {
                case 0://array
                    transaction.add(R.id.algorithm_sample_frame, new ArrayFragment());
                    transaction.commit();
                    break;
                case 1://linked list
                    transaction.add(R.id.algorithm_sample_frame, new LinkedListFragment());
                    transaction.commit();
                    break;
            }
        }
    }
}
